package com.diandian.pos.listener;


import java.io.UnsupportedEncodingException;

import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.amqp.core.Message;
import org.springframework.amqp.core.MessageListener;

import com.diandian.pos.service.ErrorMessageParseService;


/**
 * 收银错误消息上报监听
 * @author Administrator
 *
 */
public class ErrorMessageListener implements MessageListener{

    private Logger log = LoggerFactory.getLogger(ErrorMessageListener.class);


    private ErrorMessageParseService service;

    public void start() {
        this.service = new ErrorMessageParseService();
        this.service.init();
    }


	@Override
	public void onMessage(Message message) {
		//String msg = new String(message.getBody(), "utf-8");
		byte[] body = message.getBody();
		String msg = "";
		try {
			msg = new String(body, "utf-8");
		} catch (UnsupportedEncodingException e) {
			log.error("编码异常:",e);
		}
        log.info("the msg is " + msg);
        String result = service.parse(msg);
        log.info("parse result is  " + result);
	}


}
